<?php

namespace App\Listeners\Reply;

use App\Common\Libs\Dispatch\Queue;
use App\Consts\GlobalQueueConst;
use App\Events\Reply\DelReplyEvent;
use App\Jobs\Controller\MessageJob;
use App\Listeners\BaseListener;

class DelReplyListener extends BaseListener
{
    /**
     * Handle the event.
     *
     * @param DelReplyEvent $event
     * @return bool
     */
    public function handle(DelReplyEvent $event)
    {
        $this->saveFileLog(__CLASS__, $event);

        $reply = $event->reply;

        // 队列更新【评论】的【可见性】和【删除态】
        service()->CommentService->changeStatusByQueue([
            'comment_id' => $reply['comment_id'],
            'target_id' => $reply['target_id'],
            'target_type' => $reply['target_type'],
        ]);

        // 队列记录日志
        service()->LogCountService->createLogByQueue($event->logCountLoadData);

        /**
         * 队列删除：
         *  1. 该评论的：【我发出的评论】【我收到的评论】【我发出的赞】【我收到的赞】
         *  2. 回复该评论的所有回复：【我发出的评论】【我收到的评论】【我发出的赞】【我收到的赞】
         */
        Queue::getInstance(MessageJob::class)
            ->push([
                'reply_id' => $reply['reply_id']
            ], GlobalQueueConst::MESSAGE_DEL_REPLY);

        return true;
    }
}
